<{include file="Public/top.html" }>
<style>
    .ui-table th, .ui-table td{white-space: inherit;}
</style>
	</head>
	<body>
		<div id="warpper">
            <div class="content">
                <div class="location">会员活动</div>
                <{include file="./nav.html" }>
                <div class="filedSet" style="padding-bottom: 0;">
                    <div class="search">
                        <form action="" id="searchForm" method="get" class="ui-form reportForm">
                            <input name="m" type="hidden" value="<{$module}>">
                            <input name="c" type="hidden" value="<{$controller}>">
                            <input name="a" type="hidden" value="applyList">
                            <input name="id" type="hidden" value="<{$id}>">

                            <input name="p" id="page" type="hidden" value="<{$page|default:1}>">
                            <input name="limit" id="limit" type="hidden" value="<{$limit|default:10}>">

                            <div class="ui-form-item inline-block">
                                <label class="ui-label">昵称</label>
                                <input type="text" value="<{$nickname}>" class="ui-text bg-text keyword" name="nickname" placeholder="昵称" style="width: 80px;" />
                            </div>
                            <div class="ui-form-item inline-block">
                                <label class="ui-label">手机号</label>
                                <input type="text" value="<{$phone}>" class="ui-text bg-text keyword" name="phone" placeholder="手机号" style="width: 80px;" />
                            </div>
                            <div class="ui-form-item inline-block">
                                <label class="ui-label">状态</label>
                                <select name="status" class="ui-select" >
                                    <option value="0">选择状态</option>
                                    <{foreach from=$statusArray key=key item=item}>
                                        <option <{if $key == $status}>selected<{/if}> value="<{$key}>"><{$item}></option>
                                    <{/foreach}>
                                </select>
                            </div>
                            <div class="ui-form-item inline-block">
                                <label class="ui-label">活动</label>
                                <select name="eid" class="ui-select" >
                                    <option value="0">选择活动</option>
                                    <{html_options options=$eventKV selected=$id}>
                                </select>

                            </div>
                            <div class="ui-form-item inline-block">
                                <label class="ui-label">直接入选</label>
                                <input type="checkbox" value="1" class="ui-checkbox" name="useVip" <{if $useVip eq 1}>checked<{/if}> />
                            </div>

                            <div class="ui-form-item inline-block">
                                <button type="submit" class="ui-button" onclick="LayerShow();">搜索</button>
                                <button type="button" onclick="exportData();" class="ui-button">导出</button>
                            </div>
                        </form>

                    </div>
                </div>


                <!--表格内容-->
                <div class="mainGrid">
                    <table class="ui-table ui-body">
                        <thead>
                        <tr>
                            <th class="pct30">活动名</th>
                            <th class="pct10">昵称</th>
                            <th class="pct10">真实姓名</th>
                            <th class="pct20">手机号码</th>
                            <th class="pct10">数据</th>
                            <th class="pct15">报名时间</th>
                            <th class="pct20">留言</th>
                            <th class="pct20">分享图片</th>
                            <th class="pct15">宝贝信息</th>
                            <th class="pct10">其它信息</th>
                            <th class="pct10">状态</th>
                            <th class="pct20 last-col">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <{foreach from=$list item=item}>
                        <tr >
                            <td><{$item['title']}></td>
                            <td><{$item['nickname']}></td>
                            <td><{$item['realName']}></td>
                            <td><{$item['phone']}></td>

                            <td >报名:<{$item.applyCount}><br/>
                                选中:<{$item.applySelectedCount}><br/>
                                放鸽子:<{$item.applySelectedBadCount}>
                            </td>
                            <td><{$item['addTime']|date_format:"%Y-%m-%d <br/> %H:%M:%S"}>
                                <br/>
                                最近入选:<br /><{$item.lastChosenTime|date_format:"%Y-%m-%d"}>
                            </td>
                            <td><{$item['mark']}></td>
                            <td>
                                <{if $item['sharePic']}>
                                <img class="sharePic" src="<{$item['sharePic']}>" width="100"/>
                                <{/if}>
                            </td>
                            <td>
                                <{$item['babyNickname']}>_<{$item['babySex']}>_<{$item['age']}>
                            </td>
                            <td style="white-space: nowrap;word-break: keep-all;text-overflow:initial !important;overflow: scroll">
                                <{str_replace(';','<br />',$item['ext']) }>
                            </td>

                            <td id="id_<{$item.id}>">
                                <{$statusArray[$item.status]}>
                                <{if $item.useVip eq 1}><br /> 直接入选<{/if}>
                                <{if $item.isPay eq $NEEDPAY}><br /> 待支付 <{/if}>
                                <{if $item.isPay eq $PAYEND}><br /> 已支付 <{/if}>
                            </td>
                            <td class="ta_l">
                                <div class="handler c_<{$item.id}>">
                                    <a href="javascript:seeInfo('<{$item.id}>');">详情</a>
                                    <span id="status">
                                        <{if $item.status eq 1}>
                                            <a id="acid_<{$item.id}>" href="javascript:joinCandidate('<{$item.id}>');">候选</a>
                                            <a href="javascript:cancelApply('<{$item.id}>');">取消报名</a>

                                        <{/if}>
                                        <{if $item.status eq 2}>
                                            <a id="acid_<{$item.id}>" href="javascript:uncommitted('<{$item.id}>');">未参加</a>
                                            <a href="javascript:cancelUncommitted('<{$item.id}>');">取消入选</a>
                                        <{/if}>
                                        <{if $item.status eq 3}>
                                            <a id="acid_<{$item.id}>" href="javascript:beSelected('<{$item.id}>');">入选</a>
                                        <{/if}>

                                        <{if $item.status eq 5}>
                                            <a href="javascript:beSelected('<{$item.id}>');">入选</a>
                                            <a href="javascript:cancelUncommitted('<{$item.id}>');">返回候选</a>
                                        <{/if}>

                                        <a href="javascript:uploadPhoto('<{$item.eid}>','<{$item.uid}>');">上传图片</a>


                                    </span>
                                    <span>
                                        <{if $item.task eq 1}>
                                            <{if $item['doTask'] eq 1}>
                                                <a href="javascript:void(0);" class="check" onclick="showTaskInfo('<{$item.eid}>','<{$item.uid}>')">已交作业</a>
                                            <{else}>
                                                <a href="javascript:void(0);">未交作业</a>
                                            <{/if}>
                                        <{/if}>
                                    </span>
                                </div>
                            </td>
                        </tr>
                        <{/foreach}>
                        </tbody>
                    </table>
                </div>
                <!--作业详情-->
                <div id="task">
                    <!--详情-->
                    <div id="check">

                    </div>
                </div>

                <div class="pagination">
                    <!--描述：分页-->
                    <{include file="Public/page.html" }>
                </div>
            </div>
		</div>
        <{include file="Public/foot.html" }>
	</body>
</html>
<script>
    var beSelectedUri = "<{U('Events/beSelected')}>";
    var uncommittedUri = "<{U('Events/uncommitted')}>";
    var seeInfoUri = "<{U('Events/userStatus')}>";
    var uploadPhotoUri = "<{U('Events/uploadPhoto')}>";
    var exportUri = "<{U('Events/applyList')}>";
    var senMessageUri = "<{U('Events/noTaskSendMessage')}>";

    //取消报名
    function cancelApply(id){
        $.get("<{U('cancelApply')}>"+"&id="+id,function(data){
            if(data.status==0) {
                $("#id_"+id).html('取消报名');
            }else{
                layer.msg(data.msg);
            }
        },'json');

    }

    //加入 候选
    function joinCandidate(id){
        $.get(uncommittedUri+"&id="+id+'&status=5',function(data){
            if(data.status==0) {
                $("#id_"+id).html('候选');
                $(".handler.c_"+id+" span[id='status']").empty().append('<a href="javascript:beSelected(\''+id+'\');">入选</a><a href="javascript:cancelUncommitted(\''+id+'\');">返回候选</a>');
            }else{
                layer.msg('参数有误!');
            }
        },'json');
    }

    //取消 变成 未处理
    function cancelUncommitted(id) {
        $.get(uncommittedUri+"&id="+id+'&status=1',function(data){
            if(data.status==0) {
                $("#id_"+id).html('已报名');
                $(".handler.c_"+id+" span[id='status']").empty().append('<a href="javascript:joinCandidate(\''+id+'\');">候选</a>');
            }else{
                layer.msg('参数有误!');
            }
        },'json');
    }

    //入选提示
    function beSelected(id){
        $.get(beSelectedUri+"&id="+id,function(data){
            if(data.status!=0) {
                layer.msg(data.msg);
            }else{
                if(!confirm(data.msg)){
                    return false;
                }
                beSelectedIs(id);
            }
        },'json');
    }
    //加入 入选
    function beSelectedIs(id){
        $.get(beSelectedUri+"&id="+id+"&flag=1",function(data){
            if(data.status!=0) {
                layer.msg(data.msg);
            }else{
                if(data.repage == 0){
                    window.location.reload();
                }
                $("#id_"+id).html('已入选');
                $(".handler.c_"+id+" span[id='status']").empty().append('<a href="javascript:uncommitted(\''+id+'\');">未参加</a><a href="javascript:cancelUncommitted(\''+id+'\');">取消入选</a>');
            }
        },'json');
    }

    //未参与
    function uncommitted(id) {
        if(!confirm("确定该用户未参加吗？")){
            return false;
        }
        $.get(uncommittedUri+"&id="+id+'&status=4',function(data){
            if(data.status==0) {
                $("#id_"+id).html('放鸽子');
                $(".handler.c_"+id+" span[id='status']").empty();
            }
        },'json');
    }

    //用户详情
    function seeInfo(id) {
        $.get(seeInfoUri+"&id="+id,function(data){
            if(data.status==0) {
                var details = dialog({
                    title: '详情',
                    width: 700,
                    content: data.dataHTML,
                    onshow: function(){
                        //$("#details form")[0].reset();
                    },
                });
                details.showModal();
            }
        },'json')
    }

    var details=null;
    function uploadPhoto(eid,uid){
        if(!uid){
            uid=0;
        }
        $.get(uploadPhotoUri+"&eid="+eid+"&uid="+uid,function(data){

                details = dialog({
                    title: '详情',
                    width: 500,
                    content: data,
                    onshow: function(){
                        //$("#details form")[0].reset();
                    },
                });
                details.showModal();


                $('.epic').on('mouseover',function (e) {
                    if(e.target.tagName!='IMG'){
                        return;
                    }
                    layer.closeAll();
                    var url=$(e.target).attr('src');
                    layer.tips('<img src="'+url+'" style="width:280px;height:auto;">', e.target,
                            {
                                tips:[4,'#ffffff'],
                                area: ['300px', '180px'],
                                skin:'BoxShadow',
                                time:3000
                            });

                })


            $('#uploadEventPhoto').uploader();

        },'html')

    }


    (function ($) {
        'use strict';
        $.fn.uploader = function () {
            return this.each(function () {
                var $this = $(this);
                var $file = $this.find('input[type=file]');
                $file.AjaxFileUpload({
                    action: './api.php?m=Api&c=index&a=ajaxUploadArr&from=IMG_EVENT_OVER',
                    onSubmit: function () {
                    },
                    onComplete: function (filename, response) {
                        if(response.status==0 ){
                            var $p=$('#uploadEventPhoto');
                            for(var i=0;i<response.data.length;i++){
                                if(response.data[i].id>0) {
                                    $p.before("<span class='picture_box picture_80' >" +
                                            '<div class="a-imgBox" style="display:block;">' +
                                            '<a href="javascript:void(0);" class="a-close" onclick="deleteListPic(this)"></a>' +
                                            '<img src="' + response.data[i].path + '" width="99%"  class="epic"/>' +
                                            '<input type="hidden" value="'+response.data[i].path+'" name="pic[]">'+
                                            '</div></span>');
                                }
                            }
                        }else{

                        }

                    }
                });
            });
        }
    })(jQuery);



    //名单导出
    function exportData(){
        if($("#searchForm select[name='eid']").val() == 0){
            layer.msg('请针对单个活动导出！');
            return false;
        }
        window.location.href = exportUri+'&export=1'
                +'&id='+$("#searchForm input[name='id']").val()
                +'&nickname='+$("#searchForm input[name='nickname']").val()
                +'&eid='+$("#searchForm select[name='eid']").val()
                +'&status='+$("#searchForm select[name='status']").val()
                +'&phone='+$("#searchForm input[name='phone']").val();
    }

    //未交作业客服提醒
//    function sendMessage(id){
//        $.get(senMessageUri+"&id="+id,function(data){
//            layer.msg(data.msg);
//        });
//
//    }

    //读取作业详情
    function getTaskInfo(eid,uid){
        var url = "<{U('Events/getTaskInfo')}>";
        $.getJSON(url,{eid:eid,uid:uid},function(data){
            if(data.status !=0){
                layer.msg(data.msg);
            } else{
                $("#check").html('').append(data.dataHtml);
            }
        });
    }

    //作业展示
    function showTaskInfo(eid,uid){
        getTaskInfo(eid,uid);
        var check = dialog({
            title: '作业内容',
            width: 570,
            content: $("#check"),
            onshow: function(){
//                $("#check form")[0].reset();
            },
            button:[
                {
                    value:'确定',
                    callback: function(){
                        var isPass = $("input[type=radio]:checked").val();
                        var url = "<{U('Events/changeTaskStatus')}>";
                        $.getJSON(url,{eid:eid,uid:uid,status:isPass},function(data){
                            if(data.msg){
                                layer.msg(data.msg);
                            }
                        });
                    },
                    autofocus: true
                }
            ]
        });
        check.showModal();
    }
    datePickter('startDate','endDate');



    $(document).ready(
            $('.sharePic').on('mouseover',function (e) {
                if(e.target.tagName!='IMG'){
                    return;
                }
                layer.closeAll();
                var url=$(e.target).attr('src');
                layer.tips('<img src="'+url+'" style="width:280px;height:auto;">', e.target,
                        {
                            tips:[4,'#ffffff'],
                            area: ['300px', '180px'],
                            skin:'BoxShadow',
                            time:5000
                        });

            })
    );


    function submitAdminMem(uid){
        var str=$("#adminMem").val().trim();
        $.post("<{U('saveMem')}>",{uid:uid,mem:str},function(re){ layer.msg(re.msg);},"json");
    }


    function savePhoto(){
        var data= $("#addManagerForm").serialize();
        $.post("<{U('saveEventPhoto')}>",data,function(re){
            if(re.status==0){
                details.remove();
            }
            layer.msg(re.msg);
        },'json');
    }

    //删除图片
    function deleteListPic(obj) {
        $(obj).parents('.picture_box').remove();
    }

</script>
